<template>
  <div class="mt-6 max-width" style="width: 327px">
    <v-card-title class="justify-space-between">
      <div class="subtitle-1">
        <v-icon small color="blue darken-2">mdi-label-outline</v-icon>
        标签分类
      </div>
      <div>
        <v-tooltip top>
          <template v-slot:activator="{ on }">
            <v-btn text v-on="on">
              <v-icon small color="blue darken-2">mdi-dots-horizontal</v-icon>
            </v-btn>
          </template>
          <span>所有标签</span>
        </v-tooltip>
      </div>
    </v-card-title>
    <v-card-text v-if="tagList && tagList.length>0">
      <v-chip-group
        v-model="currentTag"
        column
        active-class="primary--text"
      >
        <v-chip
          v-for="tag in tagList"
          outlined
          @click="loadBlogByTag(tag)"
        >
          {{ tag.name }}
        </v-chip>

      </v-chip-group>
    </v-card-text>
    <v-card-text v-else>
      您没有博客标签..
    </v-card-text>
  </div>
</template>

<script>
import { getTagList } from '@/api/blog'
import '@/assets/css/business/blog/board/board.scss'
import { mixin } from '@/utils/mixin'

export default {
  name: 'TagBoard',
  mixins: [mixin],
  data: () => ({
    tagList: []
  }),

  created() {
    this.getBlogTags()
  },
  mounted() {

  },
  methods: {
    // 加载标签列表
    getBlogTags() {
      getTagList().then(res => {
        const result = res.data
        if (res && res.code === 200) {
          this.tagList.push(...result)
        }
      }).catch(function(e) {
        // console.log('加载标签列表失败', e)
      })
    },
    // 根据标签获取博客
    loadBlogByTag(tag) {
      // 当前选中的博客标签--存储到store中
      this.$store.commit('setBlogTag', tag.id)
    }
  }

}
</script>

<style scoped>

</style>
